<template>
  <div>
    <!-- 搜索栏 -->
    <van-search
      v-model="value"
      placeholder="请输入小区或地址"
      show-action
      background="#4fc08d"
    >
      <template #left>
        <span class="back"
          ><van-icon color="white" size="20" name="arrow-left"
        /></span>
      </template>
      <template #label>
        <span class="city" @click="$router.push('/city')">{{
          city.label
        }}</span>
      </template>
      <template #action>
        <van-icon
          name="location-o"
          size="20"
          color="#fff"
          @click.native="$router.push('/map')"
        />
      </template>
    </van-search>
    <!-- 下拉菜单 -->
    <van-dropdown-menu active-color="#21b97a">
      <van-dropdown-item title="区域">
        <van-picker
          show-toolbar
          toolbar-position="bottom"
          :columns="columns1"
        />
      </van-dropdown-item>
      <van-dropdown-item title="方式">
        <van-picker
          show-toolbar
          toolbar-position="bottom"
          :columns="columns2"
        />
      </van-dropdown-item>
      <van-dropdown-item title="租金">
        <van-picker
          show-toolbar
          toolbar-position="bottom"
          :columns="columns3"
        />
      </van-dropdown-item>
      <van-dropdown-item title="筛选" @open="showPopup"></van-dropdown-item>
    </van-dropdown-menu>
    <van-popup
      v-model="show"
      position="right"
      :style="{ height: '100%', width: '80%' }"
    >
      <div>
        <div class="dt-box">户型</div>
        <div class="dd-box">
          <span>一室</span>
          <span>二室</span>
          <span>三室</span>
          <span>四室</span>
          <span>四室+</span>
        </div>
        <div class="dt-box">朝向</div>
        <div class="dd-box">
          <span>东</span>
          <span>西</span>
          <span>南</span>
          <span>北</span>
          <span>东南</span>
          <span>东北</span>
          <span>西南</span>
          <span>西北</span>
        </div>
        <div class="dt-box">楼层</div>
        <div class="dd-box">
          <span>高楼层</span>
          <span>中楼层</span>
          <span>低楼层</span>
        </div>
        <div class="dt-box">房屋亮点</div>
        <div class="dd-box">
          <span>集中供暖</span>
          <span>双卫生间</span>
          <span>近地铁</span>
          <span>随时看房</span>
          <span>精装</span>
          <span>公寓</span>
          <span>独立卫生间</span>
          <span>押一付一</span>
          <span>独立阳台</span>
          <span>月租</span>
          <span>限女生</span>
          <span>限男生</span>
          <span>新上</span>
        </div>
      </div>
      <div class="btns">
        <van-button block>取消</van-button>
        <van-button type="primary" block>确认</van-button>
      </div>
    </van-popup>
    <!-- 房屋列表 -->
    <van-card
      v-for="(item, index) in houseList"
      :key="index"
      num="2"
      price="2.00"
      desc="描述信息"
      title="商品标题"
      :thumb="'http://liufusong.top:8080' + item.houseImg"
    />
  </div>
</template>

<script>
import { findHouse } from '@/api/find'
export default {
  name: 'find-page',
  components: {},
  props: {},
  data() {
    return {
      value: '',
      show: false,
      city: JSON.parse(window.localStorage.getItem('city')) || {
        label: '上海',
        value: 'AREA|dbf46d32-7e76-1196',
        pinyin: 'shanghai',
        short: 'sh'
      },
      houseList: [],
      columns1: [
        {
          text: '浙江',
          children: [
            {
              text: '杭州',
              children: [{ text: '西湖区' }, { text: '余杭区' }]
            },
            {
              text: '温州',
              children: [{ text: '鹿城区' }, { text: '瓯海区' }]
            }
          ]
        },
        {
          text: '福建',
          children: [
            {
              text: '福州',
              children: [{ text: '鼓楼区' }, { text: '台江区' }]
            },
            {
              text: '厦门',
              children: [{ text: '思明区' }, { text: '海沧区' }]
            }
          ]
        }
      ],
      columns2: ['不限', '整租', '合租'],
      columns3: [
        '不限',
        '1000及一下',
        '1000-2000',
        '2000-3000',
        '3000-4000',
        '4000-5000',
        '5000-7000',
        '7000以上'
      ]
    }
  },
  computed: {},
  watch: {},
  async created() {
    const res = await findHouse({ cityId: this.city.value })
    console.log(res)
    this.houseList = res.body.list
  },
  methods: {
    showPopup() {
      this.show = true
    }
  }
}
</script>

<style scoped lang="less">
.city {
  position: relative;
}
.van-search__label {
  margin-right: 20px;
  .city::after {
    content: '';
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 6px 5px 0 5px;
    border-color: #cccccf transparent transparent transparent;
    display: block;
    position: absolute;
    top: 5px;
    right: -16px;
    margin-left: 10px;
  }
}
.back {
  margin-right: 20px;
}
::v-deep .van-picker__cancel {
  flex: 1;
  color: #21b97a;
}
::v-deep .van-picker__confirm {
  flex: 2;
  background-color: #21b97a;
  color: #fff;
}
.van-popup--right {
  padding: 0 15px;
  .btns {
    display: flex;
    margin: 30px -15px 0;
    position: sticky;
    bottom: 0;
    .van-button:first-child {
      flex: 1;
    }
    .van-button:last-child {
      flex: 2;
    }
  }
}
.dt-box {
  margin: 20px 0;
  font-size: 15px;
  color: #333;
}
.dd-box {
  display: block;
  margin-left: 40px;
  padding-bottom: 14px;
  border-bottom: 1px solid #e5e5e5;
  span {
    display: inline-block;
    height: 32px;
    width: 70px;
    margin: 0 18px 15px 0;
    border: 1px solid #ddd;
    border-radius: 3px;
    line-height: 32px;
    text-align: center;
    font-size: 12px;
    color: #888;
  }
}
</style>
